<template>
  <view v-if="goods_info_item.goods_name" class="goods_info_container">
    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
      <swiper-item v-for="(item,i) in goods_info_item.pics" :key="i">
        <image :src="item.pics_big" mode="" @click="preview(i)"></image>
      </swiper-item>
    </swiper>
    <!-- 商品信息区域 -->
    <view class="goods-info-box">
      <!-- 商品价格 -->
      <view class="price">￥{{goods_info_item.goods_price}}</view>
      <!-- 商品价格 -->
      <!-- 商品主体区域 -->
      <view class="goods-info-body">
        <!-- 商品名称 -->
        <view class="goods_name">{{goods_info_item.goods_name}}</view>
        <!-- 商品收藏 -->
        <view class="favi">
          <uni-icons type="star" size="18" color="gray"></uni-icons>
          <text>收藏</text>
        </view>
      </view>
      <!-- 商品主体区域 -->
      <!-- 运费 -->
      <view class="yf">快递：免运费</view>
    </view>
    <!-- 商品信息区域 -->
    <rich-text :nodes="goods_info_item.goods_introduce"></rich-text>
    <view class="goods_nav">
      <!-- fill 控制右侧按钮的样式 -->
      <!-- options 左侧按钮的配置项 -->
      <!-- buttonGroup 右侧按钮的配置项 -->
      <!-- click 左侧按钮的点击事件处理函数 -->
      <!-- buttonClick 右侧按钮的点击事件处理函数 -->
      <uni-goods-nav :fill="true"  :options="options" :buttonGroup="buttonGroup"  @click="onClick" @buttonClick="buttonClick" />
    </view>
  </view>
  
</template>

<script>
  export default {
    data() {
      return {
        goods_info:{
          goods_id:''
        },
        goods_info_item:[],
         options: [{
        			icon: 'shop',
        			text: '店铺',
        			infoBackgroundColor:'#007aff',
        			infoColor:"red"
        		}, {
        			icon: 'cart',
        			text: '购物车',
        			info: 3
        		}],
        	    buttonGroup: [{
        	      text: '加入购物车',
        	      backgroundColor: '#ff0000',
        	      color: '#fff'
        	    },
        	    {
        	      text: '立即购买',
        	      backgroundColor: '#ffa200',
        	      color: '#fff'
        	    }
        	    ]
      };
    },
    onLoad(options) {
      // console.log(options.goods_id)
      this.goods_info.goods_id=options.goods_id
      this.getGoods_info()
    },
    methods:{
      async getGoods_info(){
        const {data:res} =await uni.$http.get('/api/public/v1/goods/detail',this.goods_info)
        if(res.meta.status !== 200) return uni.$showMsg()
        console.log(res)
        // res.message.goods_introduce=res.message.goods_introduce.replace(/<img /g,'<img style="display:block;"').replace(/webp/g,'jpg')
        // <img style=\"display:block;\"data-src=\"//image.suning.cn/uimg/sop/commodity/966602987133443585157120_x.jpg?from=mobile&format=80q.webp\" alt=\"\" src=\"//image.suning.cn/uimg/sop/commodity/966602987133443585157120_x.jpg?from=mobile&format=80q.webp\" width=\"100%\" height=\"auto\">
        this.goods_info_item=res.message
      },
      preview(i){
        uni.previewImage({
          current:i,
          // 不懂注意注意
          urls:this.goods_info_item.pics.map(x=>x.pics_big)
        })
      },
      onClick(e){
        console.log(e)
        if(e.content.text==='购物车'){
          uni.switchTab({
            url:'../../pages/cart/cart'
          })
        }
      }
    }
  }
</script>

<style lang="scss">
swiper{
  height: 750rpx;
  image{
    width: 100%;
    height: 100%;
  }
}
.goods-info-box{
  padding: 10px 10px;
  .price{
    color: #c00000;
    font-size: 20px;
  }
  .goods-info-body{
    display: flex;
    .goods_name{
      width: 80%;
      font-size: 13px;
      border-right: 1px solid #ccc;
    }
    .favi{
      width: 100px;
      font-size: 12px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      text{
        color: #ccc;
      }
    }
  }
  .yf {
      margin: 10px 0;
      font-size: 12px;
      color: gray;
    }
}
.goods_nav{
  position: sticky;
  left: 0;
  bottom: 0;
  width: 100%;
}
.goods_info_container{
  padding-bottom: 50px;
}
</style>
